package com.study.project.utils;

import java.util.Collection;

/**
 * Created by 24916 on 2021-12-07.
 */
public class CommonUtils {
    public static <T> boolean isNull(T... objects) {
        for (T obj : objects) {
            if (null == obj) {
                return true;
            }
        }
        return false;
    }

    public static <T> boolean notNull(T... objects) {
        for (T obj : objects) {
            if (null == obj) {
                return false;
            }
        }
        return true;
    }

    public static boolean isBlank(String... objects) {
        for (String obj : objects) {
            if (null == obj || obj.isEmpty()) {
                return false;
            }
        }
        return true;
    }

    public static boolean notBlank(String... objects) {
        for (String obj : objects) {
            if (null == obj || obj.isEmpty()) {
                return true;
            }
        }
        return false;
    }

    public static boolean notEmpty(Collection collection) {

        if (isNull(collection)) {
            return false;
        }
        if (collection.size() > 0) {
            return false;
        }

        return true;
    }

    public static boolean isEmpty(Collection collection) {
        if (isNull(collection)) {
            return true;
        }
        if (collection.size() <= 0) {
            return true;
        }
        return false;
    }

    public static Long isGrpcNumberNull(long val) {
        return val == 0 ? null : val;
    }

    public static String isGrpcNumberStrNull(long val) {
        return val == 0 ? null : String.valueOf(val);
    }

    public static Integer isGrpcNumberNull(int val) {
        return val == 0 ? null : val;
    }

}
